package com.test

import com.entity.PackPath
import com.utils.ScriptUtils
import com.utils.YamlUtil
import javax.script.ScriptEngineManager
import kotlin.io.path.pathString
import kotlin.test.Test

class ScriptTest {

    companion object {
        init {
            System.setProperty("LOG_PATH", ".")
        }
    }

    @Test
    fun testScriptEngineManager() {

        val manager = ScriptEngineManager();
        val engines = manager.engineFactories
        println("------------------      打印当前支持的脚本   --------------")
        engines.forEach { factory ->
            println("Engine Name: ${factory.engineName}")
            println("Engine Version: ${factory.engineVersion}")
            println("Language Name: ${factory.languageName}")
            println("Language Version: ${factory.languageVersion}")
            println("Extensions: ${factory.extensions}")
            println("Mime Types: ${factory.mimeTypes}")
            println("Names: ${factory.names}")
            println("------------------")
        }

        println(manager.getEngineByExtension("main.kts"))

    }

    @Test
    fun test() {


        ScriptUtils.initScript()


    }

    @Test
    fun testLayadcc() {

        val out = "E:\\Project\\packTest\\old"

        val files = PackPath(out).walk().filter {
            !it.pathString.contains("/update/")
        }.map {
            it.pathString
        }.toMutableSet()

        YamlUtil.loadYaml("config/config2.yml")

        ScriptUtils.initScript()
        ScriptUtils.loadFile("data/script/LayaDcc2.kts")

        ScriptUtils.scriptEngine.put("outFilePath", out)
        ScriptUtils.scriptEngine.put("myFiles", files)

        val dcc = """

            val te: Set<String> = myFiles as Set<String>
            layadcc(outFilePath, te)

        """.trimIndent()

        ScriptUtils.runScript("test", dcc).eval()

    }

}